<?php
abstract class inputset extends validatableinput {
	public $width = 1; //of the display grid
	public $values = array();
	public $checkedvalues = array();
	public $tag;
	
	public function setValues($arr){
		if ( is_array($arr)){
			foreach ( $arr as $key =>  $value){
				$this->addValue($key , $value);
			}
		}
	}
	
	public function addValue($realvalue, $displayvalue=''){
		$this->values[$realvalue] = empty($displayvalue)? $realvalue : $displayvalue;
		if ( ! isset($this->checkedvalues[$realvalue]) ){
			$this->checkedvalues[$realvalue] = 0;
		}
	}

	//sets the width of the display grid
	public function setWidth($width = 1){
		$this->width = $width;
	}

	abstract public function setCheckedValue($value);
	
	public function check($value){
		$this->setCheckedValue($value);
	}
		
	public function __toString(){

		$table = new table();
		$temparr = array();
		$count = 0;
		foreach ( $this->values as $realvalue => $displayvalue){
			$input = new $this->tag();
			$input->setName($this->attributes['name']);
			$input->setValue($realvalue);
			$input->setDisplayValue($displayvalue);
			if ( in_array($realvalue, array_keys($this->checkedvalues))){
				if ( $this->checkedvalues[$realvalue] == 1){
					$input->check();
				}
			}
			$table->col($input);
			$count++;
			if($count == $this->width ){
				$table->row();
				$count = 0;
			}
		}
		if( count($temparr)){
			$table->row($temparr);
		}
		return $table->getHtml();
	}
}
?>